package com.info.zhiduoduo.admin.controller;

import com.info.zhiduoduo.admin.model.dto.account.MakerAmountDto;
import com.info.zhiduoduo.admin.model.formbean.maker.TestTaxFeeFormBean;
import com.info.zhiduoduo.admin.model.formbean.project.DelTestDataFormBean;
import com.info.zhiduoduo.admin.service.AccountService;
import com.info.zhiduoduo.admin.service.BalanceService;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.StatusMsg;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.common.utils.ContextUtil;
import com.info.zhiduoduo.common.utils.FileUtil;
import com.info.zhiduoduo.common.utils.seal.SealUtil;
import com.info.zhiduoduo.core.service.CoreTaxerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "测试项目接口")
@RestController
@RequestMapping("/test/project")
public class TestProjectController {

//
//	@Resource
//	BalanceService balanceService;
//
//	@Resource
//	AccountService accountService;
//
//	@Autowired
//	CoreTaxerService coreTaxerService;
//
//	/**
//	 * 测试项目款项的高低限额税金和服务费计算逻辑
//	 */
//	@GetMapping("/testTransactional")
//	public SmartResult testTransactional() {
//		return testProjectService.testTransactional();
//	}
//
//	/**
//	 * 测试项目款项的高低限额税金和服务费计算逻辑
//	 */
//	@PostMapping("/testExceptionPrinter")
//	public SmartResult testTaxFee(@RequestParam String name, @RequestBody BaseSimpleFormBean formBean) {
//		throw new RuntimeException("这是一个测试信息");
//	}
//
//	/**
//	 * 测试项目款项的高低限额税金和服务费计算逻辑
//	 */
//	@PostMapping("/testTaxFee")
//	public SmartResult<TestTaxFeeDto> testTaxFee(@RequestBody BaseSimpleFormBean<TestTaxFeeFormBean> formBean) {
//		return testProjectService.testCalcStudioTaxFee(formBean);
//	}
//
//	/**
//	 * 删除测试的数据
//	 */
//	@PostMapping("/delTestData")
//	public SmartResult delTestData(@RequestBody BaseSimpleFormBean<DelTestDataFormBean> formBean) {
//		return testProjectService.delTestData(formBean);
//	}
//
//	@GetMapping("/ceshi")
//	public void ceshi() {
//		balanceService.queryDeShiYingShengBalance();
//	}
//
//	// 测试 对创客 进行周期内 统计交易 金额
//	@GetMapping("/amount")
//	public void ceshiamount() {
//		accountService.statisticsMakerAccountTotalTransaction();
//	}
//
//	@ApiOperation("测试创客众包项目(测试环境专用)")
//	@PostMapping("/testCrowdsourceProject")
//	public SmartResult testCrowdsourceProject(@RequestBody BaseSimpleFormBean<TestTaxFeeFormBean> formBean) {
//		return SmartResult.success(testProjectService.testCrowdsourceProject(formBean));
//	}
//
//	@ApiOperation("测试计算服务费(测试环境专用)")
//	@GetMapping("/testTaxerServiceCharge")
//	public SmartResult testTaxerServiceCharge(int userid, BigDecimal amount, int count) {
//		if (ContextUtil.isProd()) return SmartResult.fail(StatusMsg.StatusMsg_199);
//		return SmartResult.success(testProjectService.testInvoiceServiceCharge(userid, amount, count));
//	}
//
//	@ApiOperation("删除测试年数据(测试环境专用)")
//	@GetMapping("/deleteTestYearData")
//	public SmartResult deleteTestYearData(int userid) {
//		if (ContextUtil.isProd()) return SmartResult.fail(StatusMsg.StatusMsg_199);
//		testProjectService.deleteYearTaxerTestData(userid);
//		return SmartResult.success();
//	}
//
//	@ApiOperation("删除测试年数据(测试环境专用)")
//	@GetMapping("/deleteQuarterTestData")
//	public SmartResult deleteQuarterTestData(int userid, int quarter) {
//		if (ContextUtil.isProd()) return SmartResult.fail(StatusMsg.StatusMsg_199);
//		testProjectService.deleteQuarterTaxerTestData(userid, quarter);
//		return SmartResult.success();
//	}
//
//	@ApiOperation("获取创客年/季度/月金额")
//	@GetMapping("/getMakerAmount")
//	public SmartResult getMakerAmount(int userid, int compid, int calcAmountType, int year, int month) {
//		MakerAmountDto makerAmount = testProjectService.getMakerAmount(userid, compid, calcAmountType, year, month);
//		return SmartResult.success(makerAmount);
//	}
//
	@GetMapping(value = "/getimage",produces = MediaType.IMAGE_JPEG_VALUE)
	@ApiOperation("获取合同公章")
	@ResponseBody
	public BufferedImage getImage(String name, HttpServletResponse servletResponse) {

		BufferedImage bufferedImage = SealUtil.createSimpleCircleSealLocal(name);
		ServletOutputStream os = null;
		try {
			os = servletResponse.getOutputStream();
			ImageIO.write(bufferedImage, "PNG",os);
			os.flush();
			os.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bufferedImage;

	}

	@GetMapping(value = "/getimageS",produces = MediaType.IMAGE_JPEG_VALUE)
	@ApiOperation("获取合同公章")
	@ResponseBody
	public BufferedImage getImageS(String name, HttpServletResponse servletResponse) {

		BufferedImage bufferedImage = SealUtil.createSimpleCircleSealLocals(name);
		ServletOutputStream os = null;
		try {
			os = servletResponse.getOutputStream();
			ImageIO.write(bufferedImage, "PNG",os);
			os.flush();
			os.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bufferedImage;

	}
//
}
